
<?php

include("./PDO/PdoConnect.php"); //On inclut la connexion à la base de données.
include("./PDO/PdoNews.php"); //On inclut les fonctions PDO (create / update etc...)
require("./class/News.php"); //On requiere le fichier.

if (isset($_GET['action'])) {
    $action = $_GET['action'];
}

switch ($action) {
    case "ajouter": //On inclut la page pour ajouter une news.
        include("./page/news/ajouter.php");
        break;
    case "traitement_ajout": //On inclut la page qui insère la news en base.
        $news = new News();
        $news->setTitreNews($_POST['TITRENEWS']);
        $news->setContenuNews($_POST['CONTENUNEWS']);
        $news->setDateNews($_POST['DATENEWS']);
        $news->setTypeNews($_POST['TYPENEWS']);
        $news->setIdAdmin($_POST['IDADMIN']);
        $oPDO = new PdoNews();
        $oPDO->create($news);
        break;
    case "lister":
        $oPDO = new PdoNews();
        $lesNews = $oPDO->readAll(); //ligne est un array contenant toutes les newss
        include("./page/news/lister.php");
        break;
    case "modifier":
        include("./page/news/modifier.php");
        break;
    case "traitement_modif":
        $news = new News();
        $news->setIdNews($_POST['IDNEWS']);
        $news->setTitreNews($_POST['TITRENEWS']);
        $news->setContenuNews($_POST['CONTENUNEWS']);
        $news->setDateNews($_POST['DATENEWS']);
        $news->setTypeNews($_POST['TYPENEWS']);
        $news->setIdAdmin($_POST['IDADMIN']);

        $pdo = new PDONews();
        $pdo->update($news);
        break;
    case "supprimer":
        $news = new News();
        $news->setIdNews($_GET['IDNEWS']);
        $oPDO = new PdoNews();
        $oPDO->delete($news);
        break;
}